import json
import requests

from ttzScrapyProject.utils import HttpUtils
from ttzScrapyProject.vo.LoginUserVo import UserVo

def accountLogin(params,loginUserVo):
    # Define the URL for the GET request
    url = "http://webapicname.coo456.com/apiNew/H5login"
    # Send the GET request with parameters and store the response
    response = requests.get(url, params=params)
    response.encoding = 'utf-8'
    # Print the response content
    data=json.loads((response.content))

    if data["Code"] == 200:
        token = data["Data"]["Token"]
        loginUserVo.setUserToken(token)
    else:
        loginUserVo.setUserToken("")
    return loginUserVo

# http://webapicname.coo456.com/apiNew/slide?token=94c32f8ae3431810b3b4f16fd4581b3c&client=app&type=h5&slide_id=26
def accountLogout(self, userToken):
    logoutUrl = f"http://webapicname.coo456.com/apiNew/slide?token={userToken}&client=app&type=h5&slide_id=26"
    logoutResp = HttpUtils.get("用户登出接口", logoutUrl)

def login(self, response):
    successCode = self.settings.get("SUCCESS_CODE")
    data = json.loads((response.body))
    print(data["Code"])
    if data["Code"] == successCode:
        return data
    else:
        return ""


def getUserInfo(self, response):
    successCode = self.settings.get("SUCCESS_CODE")
    data = json.loads((response.body))
    print(data["Code"])
    if data["Code"] == successCode:
        return data
    else:
        return ""
